<?=View::factory('admin/common/header')?>
<?=HTML::style ('scripts/swfupload/simple/swfupload.css')?>
<?=HTML::script('scripts/swfupload/swfupload.js')?>
<?=HTML::script('scripts/swfupload/simple/settings.js')?>
<div id="content">
  <div class="breadcrumb">
    <a href="<?=URL::site('admin')?>">管理首页</a>
    &raquo; <a href="<?=URL::site('admin/store_item')?>">商品列表</a>
    &raquo; 添加商品
  </div>
  <?=View::factory('admin/common/message')?>
  <div class="box">
    <div class="heading">
      <h1><img src="<?=URL::site()?>images/admin/layout.png" alt="" /> 添加商品</h1>
      <div class="buttons">
        <input type="button" onclick="ajax_post();" class="btn45" value="保存" /> &nbsp;
        <input type="button" onclick="history.back();" class="btn45" value="返回" />
      </div>
    </div>
    <div class="content">
      <form method="post" enctype="multipart/form-data" id="form" onsubmit="return ajax_post();">
        <table class="form">
          <tr>
            <td width="120">商品标题 <span class="required">*</span></td>
            <td><input type="text" size="80"  maxlength="100" name="title" /></td>
          </tr>
          <tr>
            <td>分类 <span class="required">*</span></td>
            <td>
              <? foreach ($config->categories as $key => $val): ?>
                <label style="display:inline-block;width:110px;"><input type="checkbox" name="categories[]" value="<?=$key?>" /> <?=$val?></label>
              <? endforeach; ?>
            </td>
          </tr>
          <tr>
            <td>规格</td>
            <td><input type="text" size="30" maxlength="100" name="spec" /></td>
          </tr>
          <tr>
            <td valign="top">功能</td>
            <td>
              <? foreach ($config->attributes as $attr): ?>
                <label style="display:inline-block;width:110px;"><input type="checkbox" name="attributes[]" value="<?=$attr?>" /> <?=$attr?></label>
              <? endforeach; ?>
            </td>
          </tr>
          <tr>
            <td>适用皮肤</td>
            <td>
              <select name="skins">
              <? foreach ($config->skins as $skin): ?>
                <option value="<?=$skin?>"><?=$skin?></option>
              <? endforeach; ?>
              </select>
            </td>
          </tr>
          <tr>
            <td valign="top">商品简介 <span class="required">*</span></td>
            <td><textarea name="summary" style="width:500px" rows="3"></textarea></td>
          </tr>
          <tr>
            <td valign="top">商品内容 <span class="required">*</span></td>
            <td><?=Editor::factory(NULL, array('instance' => 'iEditor', 'name' => 'intro', 'upload' => TRUE))?></td>
          </tr>
          <tr>
            <td valign="top">使用方法</td>
            <td><?=Editor::factory(NULL, array('instance' => 'uEditor', 'name' => 'usage', 'height' => 200, 'upload' => TRUE))?></td>
          </tr>
          <tr>
            <td valign="top">商品图片 <span class="required">*</span></td>
            <td>
              <input type="hidden" name="image_md5" value="" />
              <div id="swfuploader"></div>&nbsp;&nbsp;
              <div id="preview_image" style="border:1px solid #CCC;width:200px;padding:1px;display:none;margin-bottom:10px;"><img src="about:blank" style="display:block" /></div>
              <div id="delete_image" style="display:none">[ <a href="javascript:;" onclick="del_image();">删除图片</a> ]</div>
            </td>
          </tr>
          <tr>
            <td>是否显示</td>
            <td>
            <label><input type="radio" name="is_show" checked="checked" /> 显示</label> &nbsp;
            <label><input type="radio" name="is_show" /> 隐藏</label> &nbsp;
            </td>
          </tr>
        </table>
      </form>
    </div>
</div>
<?=View::factory('admin/common/footer')?>
<script type="text/javascript">
function del_image() {
    $('#preview_image').hide().find('img').attr('src', 'about:blank');
    $('#delete_image').hide();
}
function ajax_post() {
    iEditor.sync();
    uEditor.sync();
    return $('#form').ajax_post({
        redirect :'<?=Helper::factory('redirect')->get(URL::site('admin/store_item'))?>'
    });
}
$().ready(function(){
    $('#store_item').addClass('selected');

    $('#swfuploader').swfupload({
        button_text : '上传商品图片',
        button_text_left_padding : 7,
        file_size_limit : '2 MB',
        upload_url : '<?=URL::site('admin/swfupload/item')?>',
        post_params : { session_id : '<?=Session::instance()->id()?>' },
        custom_settings : {
            session_url : '<?=URL::site('admin/swfupload/session')?>',
            success_callback : function(data, settings){
                $('#preview_image').show().find('img').attr('src', data.cover);
                $('#delete_image').show();
                $('input[name=image_md5]').val(data.base);
                alert('商品图片上传成功！');
            }
        }
    });
});
</script>